Technical Q&A QA1024
DeviceLoop is for drawing


Q: Why do I have problems when I use DeviceLoop for non-drawing-related tasks like finding out which screens contain a given rectangle?

A: Because DeviceLoop should only be used for drawing, not for other tasks. Among other things, DeviceLoop assumes a valid current port which cannot always be guaranteed when called at other times. Also, DeviceLoop has a substantial overhead and can adversely affect performance because it needs to save and restore state information in the port.



/* To determine which devices intersect a given rectangle
in global coordinates, you can use this function from
CGDirectDisplay.h See Technote 2007 for more information */

CGDisplayErr  CGGetDisplaysWithRect(
    CGRect rect,
    CGDisplayCount maxDisplays,
    CGDirectDisplayID * dspys,
    CGDisplayCount * dspyCnt);


/* Or use the Display Manager in a loop */
for (GDHandle gdh = DMGetFirstScreenDevice(TRUE);
        gdh != 0;
        gdh = DMGetNextScreenDevice(gdh, TRUE))
{
    /* compare (**gdh).gdRect with your window's bounds */
}

Listing 1. Finding Displays Intersecting a Given Rectangle



If you need to find out which monitors intersect a given rectangle (a common misuse of DeviceLoop), see the code in Listing 1 above.


[Apr 11 2001]


Developer Documentation | Technical Notes | Development Kits | Sample Code